package com.winxuan.channel.support.interceptor;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.security.core.Authentication;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.winxuan.channel.model.member.User;
import com.winxuan.channel.support.interceptor.security.SecurityCoreInterceptor;

/**
 * @ MemberInterceptor.java 
 * To:������ -�����û���Ϣ
 * Warn:

 * Note:winxuan.com
 * VERSION       DATE            BY       CHANGE/COMMENT
 * 1.0          2011-5-10          HideHai         2011-5-10
 */
public class MemberInterceptor extends HandlerInterceptorAdapter{

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		if(handler instanceof MemberAware){
			MemberAware aware = (MemberAware) handler;
			HttpSession session = request.getSession(false);
			if(session!=null 
					&& session.getAttribute(SecurityCoreInterceptor.SPRING_SECURITY_SESSION_ID) != null){
				Authentication authentication = (Authentication) session.getAttribute(SecurityCoreInterceptor.SPRING_SECURITY_SESSION_ID);
				User user = (User) authentication.getPrincipal();
				if(user != null)
				aware.setCustomer(user);
			}
		}
		super.postHandle(request, response, handler, modelAndView);
	}
  
}
